package com.atguigu.gulimail.member.controller;

import java.util.Arrays;
import java.util.Map;

//import com.atguigu.gulimail.member.configuration.DoexecuteRestTemplate;
import com.atguigu.gulimail.member.feign.CouponService;
import com.atguigu.gulimail.member.feign.CouponSpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atguigu.gulimail.member.entity.UserEntity;
import com.atguigu.gulimail.member.service.UserService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;


/**
 * 用户表
 *
 * @author dengjizheng
 * @email dengjizheng@gmail.com
 * @date 2021-06-27 16:08:01
 */
@RestController
@RequestMapping("member/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    CouponService couponService;

    @Autowired
    CouponSpuService couponSpuService;

//    @Autowired
//    DoexecuteRestTemplate doexecuteRestTemplate;

    @RequestMapping("/coupon")
    public R test(){
        UserEntity userEntity = new UserEntity();
        userEntity.setNickname("王小二");

        R memberCoupons = couponService.getMemberCoupon();
        return R.ok().put("member",userEntity).put("memberCoupons",memberCoupons.get("name"));
    }

    @RequestMapping("/coupon/spu")
    public R selectSpuInfo(){
        R s =  couponSpuService.selectTest();
        return s;
    }

//    @RequestMapping("/testDoexecute")
//    public Object doExecute(){
//        return doexecuteRestTemplate.getInfo();
//    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		UserEntity user = userService.getById(id);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserEntity user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		userService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
